package com.bdk.middle.common.util;

import com.bdk.middle.common.result.ResultDO;
import com.bdk.middle.common.status.ErrorCode;
import org.apache.commons.beanutils.BeanUtils;


/**
 * @author reagan
 * @Description:实体拷贝类
 */
public class BeanUtilsExtends {

    /**
     * 拷贝数据到DTO对象
     *
     * @param dest 目标DTO
     * @param orig 源DAO
     * @return 是否拷贝成功 true成功false失败
     */
    public static boolean copyProperties(Object dest, Object orig) {
        try {
            BeanUtils.copyProperties(dest, orig);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    /* 本来就是个简单的调用还包装一个方法来这就是脱了裤子放屁
     * 拷贝DTO到实体对象
     */
    public static ResultDO copy(Object dest, Object orig) {
        ResultDO result = new ResultDO();
        try {
            copyProperties(dest, orig);
        } catch (Exception e) {
            result.setErrorCode(ErrorCode.SYSTEM_COPY_OBJECT_ERROR);
            result.setSuccess(false);
        }
        return result;
    }

}





